home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / MilkShape 3D / main.cpp < prev    next >
C/C++ Source or Header  |  2002-09-17  |  2KB  |  94 lines

  1. #include <iostream>
  2. #include <gl/glut.h>
  3. #include "data.h"
  4.  
  5. // "Object" data structure
  6. typedef struct _obj {
  7.     Point3    *vertices;
  8.     long    *v_idx;
  9.     Point3    *normals;
  10.     long    *n_idx;
  11.     Point2    *uvs;
  12.     int        num_faces;
  13. } Obj;
  14.  
  15. void reshapeFunc(int w, int h);
  16. void displayFunc();
  17.  
  18. GLfloat light_diffuse[]    =    {1.0, 0.0, 0.0, 1.0};    // red diffuse light
  19. GLfloat light_position[] =    {1.0, 1.0, 1.0, 0.0};    // infinite light position
  20.  
  21. Obj sph01;
  22.  
  23. int main(int argc, char **argv)
  24. {
  25.     glutInit(&argc, argv);
  26.     glutInitWindowSize(800,600);
  27.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
  28.     glutCreateWindow("OpenGL C++ Exporter");
  29.     glutReshapeFunc(reshapeFunc);
  30.     glutDisplayFunc(displayFunc);
  31.     glClearColor(0.2,0.5,0.5,0.0);
  32.     glEnable(GL_DEPTH_TEST);
  33.  
  34.     glLightfv    (GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
  35.     glLightfv    (GL_LIGHT0, GL_POSITION, light_position);
  36.     glEnable    (GL_LIGHT0);
  37.     glEnable    (GL_LIGHTING);
  38.  
  39.     sph01.vertices = Sphere01_vertex;
  40.     sph01.v_idx = Sphere01_vidx;
  41.     sph01.normals = Sphere01_normal;
  42.     sph01.n_idx = Sphere01_nidx;
  43.     sph01.uvs = Sphere01_uv;
  44.     sph01.num_faces = (sizeof(Sphere01_vidx)/sizeof(long));
  45.  
  46.     glutMainLoop();
  47.     
  48.     return 0;
  49. }
  50.  
  51. /*----------------------------------------------------------------------------*/
  52. /*----------------------------------------------------------------------------*/
  53.  
  54. void reshapeFunc(int w, int h)
  55. {
  56.     glViewport(0,0,w,h);
  57.     glMatrixMode(GL_PROJECTION);
  58.     glLoadIdentity();
  59.     if(h<1) h=1;
  60.     gluPerspective(40.0, (double)w/(double)h, 1.0, 1000.0);
  61.     glMatrixMode(GL_MODELVIEW);
  62. }
  63.  
  64. void displayFunc(){
  65.     static GLfloat angle1 = 0.0;
  66.     angle1 += 1.0;
  67.     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  68.     glLoadIdentity();
  69.     glTranslatef( 0.0, 0.0, -120.0 );
  70.     
  71.     glRotatef( angle1,       0.0, 1.0, 0.0 );
  72.     glRotatef( angle1 / 3.0, 1.0, 0.0, 0.0 );
  73.  
  74.     glBegin( GL_TRIANGLES );
  75.  
  76.     for(int i=0; i<sph01.num_faces; i++)
  77.     {
  78.         //--- This is how to use the provided texture coordinates
  79.         // glTexCoord2f( sph01.uvs[sph01.v_idx[i]].x, sph01.uvs[sph01.v_idx[i]].y );
  80.  
  81.         glNormal3f( sph01.normals[sph01.n_idx[i]].x,
  82.                     sph01.normals[sph01.n_idx[i]].y,
  83.                     sph01.normals[sph01.n_idx[i]].z );
  84.         glVertex3f(    sph01.vertices[sph01.v_idx[i]].x,
  85.                     sph01.vertices[sph01.v_idx[i]].y,
  86.                     sph01.vertices[sph01.v_idx[i]].z );                    
  87.     }
  88.  
  89.     glEnd();
  90.  
  91.     glutSwapBuffers();
  92.     glutPostRedisplay();
  93. }
  94.